package com.tal.bcc.pad.cloud.thread;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolManager {
    private static ThreadPoolManager mInstance;
    private int corePoolSize;
    private int maximumPoolSize;
    private long keepAliveTime = 1L;
    private TimeUnit unit;
    private ThreadPoolExecutor executor;

    public static ThreadPoolManager getInstance() {
        if (mInstance == null) {
            Class var0 = ThreadPoolManager.class;
            synchronized(ThreadPoolManager.class) {
                if (mInstance == null) {
                    mInstance = new ThreadPoolManager();
                }
            }
        }

        return mInstance;
    }

    private ThreadPoolManager() {
        this.unit = TimeUnit.HOURS;
        this.corePoolSize = 3;
        this.maximumPoolSize = this.corePoolSize;
        this.executor = new ThreadPoolExecutor(this.corePoolSize, this.maximumPoolSize, this.keepAliveTime, this.unit, new LinkedBlockingQueue(), Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
        this.executor.allowCoreThreadTimeOut(true);
    }

    public void execute(Runnable runnable) {
        if (runnable != null) {
            this.executor.execute(runnable);
        }
    }

    public void remove(Runnable runnable) {
        if (runnable != null) {
            this.executor.remove(runnable);
        }
    }

    public void shutDown() {
        if (this.executor != null && !this.executor.isShutdown()) {
            this.executor.shutdownNow();
        }

    }
}